// 键名
const INFO_KEY = 'Lin_Yuan_'
const HISTORY_KEY = 'Lin_Yuan_History_'
const CART_KEY = 'Lin_Yuan_Cart_'
const ADDRESS_KEY = 'Lin_Yuan_Address_'
const PRICE_KEY = 'Lin_Yuan_Price_'
// 获取个人信息
export const getInfo = () => {
  const info = localStorage.getItem(INFO_KEY)
  if (info) {
    return JSON.parse(info)
  } else {
    return {
      token: '',
      userId: '',
      addNum: ''
    }
  }
}
// 设置个人信息
export const setInfo = (info) => {
  localStorage.setItem(INFO_KEY, JSON.stringify(info))
}
// 清除个人信息
export const clearInfo = () => {
  localStorage.removeItem(INFO_KEY)
}
// 获取历史记录
export const getHistory = () => {
  const history = localStorage.getItem(HISTORY_KEY)
  if (history) {
    return JSON.parse(history)
  } else {
    return []
  }
}
// 设置历史记录
export const setHistory = (history) => {
  localStorage.setItem(HISTORY_KEY, JSON.stringify(history))
}
// 清除历史记录
export const clearHistory = () => {
  localStorage.removeItem(HISTORY_KEY)
}
export const getCart = () => {
  const cart = localStorage.getItem(CART_KEY)
  if (cart) {
    return JSON.parse(cart)
  } else {
    return {
      cartList: [],
      cartNum: 0
    }
  }
}
export const setCart = (cart) => {
  localStorage.setItem(CART_KEY, JSON.stringify(cart))
}
export const clearCart = () => {
  localStorage.removeItem(CART_KEY)
}
export const getAddress = () => {
  // 从localStorage中获取ADDRESS_KEY对应的值
  const address = localStorage.getItem(ADDRESS_KEY)

  // 如果获取到的address不为空
  if (address) {
    // 将获取的字符串解析为JSON对象并返回
    return JSON.parse(address)
  } else {
    // 如果获取到的address为空，返回一个空数组
    return []
  }
}
export const setAddress = (address1) => {
  localStorage.setItem(ADDRESS_KEY, JSON.stringify(address1))
}
export const clearAddress = () => {
  localStorage.removeItem(ADDRESS_KEY)
}
export const setPrice = (Price) => {
  localStorage.setItem(PRICE_KEY, JSON.stringify(Price))
}
export const getPrice = () => {
  const Price = localStorage.getItem(PRICE_KEY)
  if (Price) {
    return JSON.parse(Price)
  } else {
    return []
  }
}
export const clearPrice = () => {
  localStorage.removeItem(PRICE_KEY)
}
